package com.plant.agent.service.impl;

import com.plant.agent.domain.Agent;
import com.plant.agent.mapper.AgentMapper;
import com.plant.agent.service.AgentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class AgentServiceImpl implements AgentService {

    @Autowired
    private AgentMapper agentMapper;
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public List<Agent> findAgent() {
        return agentMapper.findAgent();
    }

    //入驻添加
    @Override
    public boolean addAgent(Agent agent) {
        agent.setStatus(2);
        Agent dname = agentMapper.findDname(agent.getDname());
        if (dname != null){
            return false;
        }
        boolean b = agentMapper.addAgent(agent);
        redisTemplate.opsForValue().set("agent",agent.getDname(),60, TimeUnit.MINUTES);
        return b;
    }

    @Override
    public Agent findAll(Integer did) {
        return agentMapper.findAll(did);
    }

    @Override
    public int updatestatus3(Integer did) {
        return agentMapper.updatestatus3(did);
    }

    @Override
    public int updatestatus4(Integer did) {
        return agentMapper.updatestatus4(did);
    }

    @Override
    public Agent findAgent2(Integer did) {
        return agentMapper.findAgent2(did);
    }
}
